Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/paymaster foundry tests #1

Merged
merged 45 commits into from
Jul 11, 2024
Merged

Conversation

ShivaanshK
Copy link
Contributor

  • Unit tests for BiconomySponsorshipPaymasterWithPremium
  • Fuzz tests for BiconomySponsorshipPaymasterWithPremium

Copy link
Contributor

@Aboudjem Aboudjem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To enhance the readability and cleanliness of your code I think you should try breaking up large blocks with new lines where appropriate. This makes the code easier to read and understand

test/foundry/base/NexusTestBase.sol Outdated Show resolved Hide resolved
vm.prank(FACTORY_OWNER.addr);
META_FACTORY.addFactoryToWhitelist(address(FACTORY));
HANDLER_MODULE = new MockHandler();
// EXECUTOR_MODULE = new MockExecutor();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code

NexusAccountFactory internal FACTORY;
BiconomyMetaFactory internal META_FACTORY;
MockHandler internal HANDLER_MODULE;
// MockExecutor internal EXECUTOR_MODULE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented code

Comment on lines 43 to 44
event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to EventsAndErrors

import { BiconomyMetaFactory } from "nexus/contracts/factory/BiconomyMetaFactory.sol";
import { MockValidator } from "nexus/contracts/mocks/MockValidator.sol";
import { MockHook } from "nexus/contracts/mocks/MockHook.sol";
// import { MockExecutor } from "nexus/contracts/mocks/MockExecutor.sol";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this

function test_SetVerifyingSigner() external {
vm.startPrank(PAYMASTER_OWNER.addr);
vm.expectEmit(true, true, true, true, address(bicoPaymaster));
emit IBiconomySponsorshipPaymaster.VerifyingSignerChanged(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@livingrockrises we should change the name of the methods / funcs that contains verifying as it is the old name and we changed it since then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is still verifyingSigner!
paymaster name change to sponsorship paymaster is good
but what do you suggest then for this verifyingSigner?

}

function test_RevertIf_UnauthorizedSetVerifyingSigner() external {
vm.startPrank(DAN_ADDRESS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prank here is not really necessary

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can call it directly imo

Comment on lines 93 to 101
function test_SetFeeCollector() external {
vm.startPrank(PAYMASTER_OWNER.addr);
vm.expectEmit(true, true, true, true, address(bicoPaymaster));
emit IBiconomySponsorshipPaymaster.FeeCollectorChanged(
PAYMASTER_FEE_COLLECTOR.addr, DAN_ADDRESS, PAYMASTER_OWNER.addr
);
bicoPaymaster.setFeeCollector(DAN_ADDRESS);
assertEq(bicoPaymaster.feeCollector(), DAN_ADDRESS);
vm.stopPrank();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check initial state

Comment on lines 104 to 102
function test_RevertIf_SetFeeCollectorToZeroAddress() external {
vm.startPrank(PAYMASTER_OWNER.addr);
vm.expectRevert(abi.encodeWithSignature("FeeCollectorCannotBeZero()"));
bicoPaymaster.setFeeCollector(address(0));
vm.stopPrank();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Comment on lines 111 to 125
function test_RevertIf_UnauthorizedSetFeeCollector() external {
vm.startPrank(DAN_ADDRESS);
vm.expectRevert(abi.encodeWithSignature("Unauthorized()"));
bicoPaymaster.setFeeCollector(DAN_ADDRESS);
vm.stopPrank();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same applies for all Unauthorized errors

@Aboudjem
Copy link
Contributor

Aboudjem commented Jul 3, 2024

there are errors on checks, please fix compiler issues and test issues

@Aboudjem
Copy link
Contributor

Aboudjem commented Jul 3, 2024

since you removed Lock consider also removing the test file on hardhat test

@ShivaanshK ShivaanshK force-pushed the feat/paymaster-foundry-tests branch from 31a4ea1 to 81abba5 Compare July 9, 2024 13:07
@livingrockrises
Copy link
Contributor

Can you also add a test for parsePaymasterAndData

assertEq(address(testArtifact.entryPoint()), ENTRYPOINT_ADDRESS);
assertEq(testArtifact.verifyingSigner(), PAYMASTER_SIGNER.addr);
assertEq(testArtifact.feeCollector(), PAYMASTER_FEE_COLLECTOR.addr);
assertEq(testArtifact.postOpCost(), 0 wei);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's set some postOpCost upon deployment..

bicoPaymaster.setPostopCost(newPostopCost);
}

function test_DepositFor() external {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just remembered depositFor when you do first time it will be cold access on paymasterIdBalances
and second time it will be warm.
so with different dapp accounts tests should keep this in mind. accounting wise too

Copy link
Contributor

@livingrockrises livingrockrises left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review i
looks good.
on naming convention of some methods may have some inputs in a bit

@livingrockrises
Copy link
Contributor

check failing CI flows as well, take help of Adam later

Copy link
Contributor

@livingrockrises livingrockrises left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@livingrockrises livingrockrises merged commit 036840b into develop Jul 11, 2024
1 of 3 checks passed
@livingrockrises livingrockrises deleted the feat/paymaster-foundry-tests branch October 7, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants